home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / GLE / HORN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.4 KB  |  138 lines

  1.  
  2. /* 
  3.  * hron -- cone drawing demo 
  4.  *
  5.  * FUNCTION:
  6.  * Baisc demo illustrating how to write code to draw
  7.  * the a slightly fancier "polycone".
  8.  *
  9.  * HISTORY:
  10.  * Linas Vepstas March 1995
  11.  */
  12.  
  13. /* required include files */
  14. #include <GL/glut.h>
  15. #include <GL/tube.h>
  16.  
  17. /* the arrays in which we will store out polyline */
  18. #define NPTS 26
  19. double radii [NPTS];
  20. double points [NPTS][3];
  21. int idx = 0;
  22.  
  23. /* some utilities for filling that array */
  24. #define PNT(x,y,z) {             \
  25.    points[idx][0] = x;             \
  26.    points[idx][1] = y;             \
  27.    points[idx][2] = z;            \
  28.    idx ++;                \
  29. }
  30.  
  31. #define RAD(r) {            \
  32.    radii[idx] = r;            \
  33. }
  34.  
  35. /* 
  36.  * Initialize a bent shape with three segments. 
  37.  * The data format is a polyline.
  38.  *
  39.  * NOTE that neither the first, nor the last segment are drawn.
  40.  * The first & last segment serve only to determine that angle 
  41.  * at which the endcaps are drawn.
  42.  */
  43.  
  44. void InitStuff (void) {
  45.  
  46.    /* initialize the join style here */
  47.    gleSetJoinStyle (TUBE_NORM_PATH_EDGE | TUBE_JN_ANGLE );
  48.  
  49.    RAD (0.3);
  50.    PNT (-4.9, 6.0, 0.0);
  51.  
  52.    RAD (0.3);
  53.    PNT (-4.8, 5.8, 0.0);
  54.  
  55.    RAD (0.3);
  56.    PNT (-3.8, 5.8, 0.0);
  57.  
  58.    RAD (0.6);
  59.    PNT (-3.5, 6.0, 0.0);
  60.  
  61.    RAD (0.8);
  62.    PNT (-3.0, 7.0, 0.0);
  63.  
  64.    RAD (0.9);
  65.    PNT (-2.4, 7.6, 0.0);
  66.  
  67.    RAD (1.0);
  68.    PNT (-1.8, 7.6, 0.0);
  69.  
  70.    RAD (1.1);
  71.    PNT (-1.2, 7.1, 0.0);
  72.  
  73.    RAD (1.2);
  74.    PNT (-0.8, 5.1, 0.0);
  75.  
  76.    RAD (1.7);
  77.    PNT (-0.3, -2.0, 0.0);
  78.  
  79.    RAD (1.8);
  80.    PNT (-0.2, -7.0, 0.0);
  81.  
  82.    RAD (2.0);
  83.    PNT (0.3, -7.8, 0.0);
  84.  
  85.    RAD (2.1);
  86.    PNT (0.8, -8.2, 0.0);
  87.  
  88.    RAD (2.25);
  89.    PNT (1.8, -8.6, 0.0);
  90.  
  91.    RAD (2.4);
  92.    PNT (3.6, -8.6, 0.0);
  93.  
  94.    RAD (2.5);
  95.    PNT (4.5, -8.2, 0.0);
  96.  
  97.    RAD (2.6);
  98.    PNT (4.8, -7.5, 0.0);
  99.  
  100.    RAD (2.7);
  101.    PNT (5.0, -6.0, 0.0);
  102.  
  103.    RAD (3.2);
  104.    PNT (6.4, -2.0, 0.0);
  105.  
  106.    RAD (4.1);
  107.    PNT (6.9, -1.0, 0.0);
  108.  
  109.    RAD (4.1);
  110.    PNT (7.8, 0.5, 0.0);
  111.  
  112. }
  113.  
  114. extern float lastx;
  115. extern float lasty;
  116.  
  117. /* draw the polycone shape */
  118. void DrawStuff (void) {
  119.  
  120.    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  121.  
  122.    /* set up some matrices so that the object spins with the mouse */
  123.    glPushMatrix ();
  124.    glTranslatef (0.0, 0.0, -80.0);
  125.    glRotatef (lastx, 0.0, 1.0, 0.0);
  126.    glRotatef (lasty, 1.0, 0.0, 0.0);
  127.    glColor3f (0.5, 0.5, 0.2);
  128.  
  129.    /* Phew. FINALLY, Draw the polycone  -- */
  130.    glePolyCone (idx, points, 0x0, radii);
  131.  
  132.    glPopMatrix ();
  133.  
  134.    glutSwapBuffers ();
  135. }
  136.  
  137. /* --------------------------- end of file ------------------- */
  138.